#include <iostream>
using namespace std;

#include "multimedia.h"
#include "multimediaRegister.h"

int main(){
	multimediaRegister mreg;
	mreg.readFile("reg.txt");

	int input;
	string type;
	string name;
	string author;
	int year;
	int length;	

	while (true)
	{

		system("cls");
		cout << "MAIN MENU: " << endl
			<< "1.) Add Multimedia" << endl
			<< "2.) Remove Multimedia" << endl
			<< "3.) Sort Register" << endl
			<< "4.) Display Register" << endl
			<< "5.) Exit" << endl;
		cin >> input;
	
		cin.get();	//clear input buffer

		switch (input){
		case 1:
			system("cls");
			cout << "Add multimedia:" << endl << endl;
			cout << "Enter Type (music (mu), movie (mo), book (b)): ";
			getline(cin, type);
			if (type == "music" || type == "mu"){
				cout << "Enter name: ";
				getline(cin, name);
				cout << "Enter Author: ";
				getline(cin, author);
				cout << "Enter year: ";
				cin >> year;
				cin.get();	//clear input buffer
				cout << "Enter length (minutes): ";
				cin >> length;
				cin.get();	//clear input buffer
				mreg.add(new music(name, author, year, length));
			}
			else if (type == "movie" || type == "mo"){
				cout << "Enter name: ";
				getline(cin, name);
				cout << "Enter Author: ";
				getline(cin, author);
				cout << "Enter year: ";
				cin >> year;
				cin.get();	//clear input buffer
				cout << "Enter length (minutes): ";
				cin >> length;
				cin.get();	//clear input buffer
				mreg.add(new movie(name, author, year, length));
			}
			else if (type == "book" || type == "b"){
				cout << "Enter name: ";
				getline(cin, name);
				cout << "Enter Author: ";
				getline(cin, author);
				cout << "Enter year: ";
				cin >> year;
				cin.get();	//clear input buffer
				cout << "Enter no. pages: ";
				cin >> length;
				cin.get();	//clear input buffer
				mreg.add(new book(name, author, year, length));
			}
			break;
		case 2:
			system("cls");
			cout << "Remove multimedia:" << endl << endl;
			cout << "Enter name: ";
			getline(cin, name);
			cout << "Enter year: ";
			cin >> year;
			cin.get();	//clear input buffer
			mreg.remove(new multimedia(name, year));
			break;
		case 3:
			system("cls");
			cout << "Sort multimedia:" << endl << endl;
			mreg.sort();
			_sleep(1000);
			cout << "Register sorted!" << endl << endl;
			system("pause");
			break;
		case 4:
			system("cls");
			mreg.display();
			cout << endl;
			system("pause");
			break;
		case 5:
			mreg.writeFile("reg.txt");
			return 0;
		default:
			break;
		}
	}
	
}